package packet;

import main.Utils;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: qiukexu
 * Date: 2009-6-2
 * Time: 16:18:59
 */
public class UUIDPacket extends Packet {
    public byte[] toBinaryData() {
        Utils utils = new Utils();
        byte[] bytes = new byte[this.getPktCtlMsg().getPackLeng()+ERROR_CODE_LENGTH+this.getData().getPackLeng()];

        System.arraycopy(this.getPktCtlMsg().toBinaryData(),0,bytes,0,this.getPktCtlMsg().getPackLeng());
        try{
            byte[] errorCodeBytes = utils.getBytes(this.getErrorCode());
            System.arraycopy(errorCodeBytes,0,bytes,this.getPktCtlMsg().getPackLeng(),ERROR_CODE_LENGTH);
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.arraycopy(this.getData().toBinaryData(),0,bytes,this.getPktCtlMsg().getPackLeng()+ERROR_CODE_LENGTH,this.getData().getPackLeng());
        
        return bytes;
    }
}
